package javaStream;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

import org.junit.Test;

public class test01Test {
	
	@Test
	public void testPrintWriter() {
		System.out.println("PrintWriter Test");
		PrintWriter out = null;
		try {
			out = new PrintWriter("student.txt");
			for (int i = 0; i < 10000000; i++) {
				out.println("1");
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			out.close();
		}
	}
	
	
	public void testBufferedReader() {
		System.out.println("BufferedReader Test");
		BufferedReader br = null;
		try {
			br = new BufferedReader(new FileReader("student.txt"));
			while( br.readLine()!=null){}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				br.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	@Test
	public void testBufferedWriter() {
		System.out.println("BufferedWriter Test");
		BufferedWriter bw = null;
		try {
			bw = new BufferedWriter(new FileWriter("student1.txt"));
			for (int i = 0; i < 10000000; i++) {
				bw.write("1");
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				bw.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
	}

	public void testScanner() {
		System.out.println("Scanner Test");
		Scanner sc = null;
		try {
			sc = new Scanner(new File("student.txt"));
			while(sc.hasNextInt()){
				sc.nextInt();
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			sc.close();
		}
	}
}
